package org.jivesoftware.smackx.ping;

import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.Set;
import org.jivesoftware.smack.Connection;

class ServerPingTask
  implements Runnable
{
  private WeakReference<Connection> weakConnection;
  private int delta = 1000;
  private int tries = 3;

  protected ServerPingTask(Connection paramConnection)
  {
    this.weakConnection = new WeakReference(paramConnection);
  }

  public void run()
  {
    Connection localConnection = (Connection)this.weakConnection.get();
    if (localConnection == null)
      return;
    if (localConnection.isAuthenticated())
    {
      PingManager localPingManager = PingManager.getInstanceFor(localConnection);
      boolean bool = false;
      for (int i = 0; i < this.tries; i++)
      {
        if (i != 0)
          try
          {
            Thread.sleep(this.delta);
          }
          catch (InterruptedException localInterruptedException)
          {
            return;
          }
        bool = localPingManager.pingMyServer();
        if (bool)
        {
          localPingManager.lastSuccessfulPingByTask = System.currentTimeMillis();
          break;
        }
      }
      if (!bool)
      {
        Set localSet = localPingManager.getPingFailedListeners();
        Iterator localIterator = localSet.iterator();
        while (localIterator.hasNext())
        {
          PingFailedListener localPingFailedListener = (PingFailedListener)localIterator.next();
          localPingFailedListener.pingFailed();
        }
      }
      else
      {
        localPingManager.maybeSchedulePingServerTask();
      }
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.ping.ServerPingTask
 * JD-Core Version:    0.6.1
 */